/**
 * create by young (young2f@outlook.com) on 2020/10/14
 */
'use strict';
import {
  getIIOTConfig,setIIOTConfig,restartIIOT,findSettings,updateSettings,findUserSettings,updateUserSettings
} from '../services/settings';
import {createDynamicLabel, deleteDynamicLabel, getDynamicLabels, updateDLabel} from '../services/dynamicLabel';


export default {
  namespace: 'settings',
  state: {},

  effects: {
    * getIIOTConfig({ payload }, { call, put }) {
      const response = yield call(getIIOTConfig, payload);
      return response;
    },
    * setIIOTConfig({ payload }, { call, put }) {
      const response = yield call(setIIOTConfig, payload);
      return response;
    },
    * restartIIOT({ payload }, { call, put }) {
      const response = yield call(restartIIOT, payload);
      return response;
    },
    * findSettings({ payload }, { call, put }) {
      const response = yield call(findSettings, payload);
      return response;
    },
    * updateSettings({ payload }, { call, put }) {
      const response = yield call(updateSettings, payload);
      return response;
    },
    * findUserSettings({ payload }, { call, put }) {
      const response = yield call(findUserSettings, payload);
      return response;
    },
    * updateUserSettings({ payload }, { call, put }) {
      const response = yield call(updateUserSettings, payload);
      return response;
    },
    // * clearSalesOrders({ payload }, { call, put }) {
    //   const response = yield call(clearSalesOrders, payload);
    //   return response;
    // },

    * getLabels({ payload }, { call, put }) {
      const response = yield call(getDynamicLabels, payload);
      // if (response) {
      //   const list = response.result;
      //   const dynamicLabels = list.filter(item => {
      //     return !item.disabled;
      //   });
      //   yield put({
      //     type: 'onDataLoad',
      //     payload: {
      //       dynamicLabels,
      //     },
      //   });
      //
      // }
      return response;
    },

    * createLabel({ payload }, { call, put }) {

      const response = yield call(createDynamicLabel, payload);
      return response;
    },

    * updateDLabel({ payload }, { call, put }) {
      const response = yield call(updateDLabel, payload);
      return response;
    },
    * deleteLabel({ payload }, { call, put }) {
      const response = yield call(deleteDynamicLabel, payload);
      return response;
    },
  },
};
